package com.cy.pj.sys.dao;


import com.cy.pj.common.pojo.SysUser;
import com.cy.pj.common.pojo.SysUserDept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SysUserDao {

    /**
     * 基于用户名查找数据库中的用户对象
     * @param username
     * @return
     */
    @Select("select * from sys_users where username = #{username}")
    SysUser findUserByUsername(String username);

    /**
     * 基于用户id获取用户以及用户对应的部门信息
     * @param id
     * @return
     */
    SysUserDept findById(Integer id);


    int updateObject(SysUser entity);
    int insertObject(SysUser entity);

    @Update("update sys_users set valid=#{valid},modifiedUser=#{modifiedUser},modifiedTime=now() where id=#{id}")
    int validById(Integer id,Integer valid,String modifiedUser);

    /**
     * 基于条件查询总记录数
     * @param username
     * @return
     */
    //int getRowCount(String username);

    // List<SysUserDept> findPageObjects(String username,Integer startIndex,Integer pageSize);

  List<SysUserDept> findPageObjects(String username);
@Update("update sys_users\n" +
        " set password=#{password},\n" +
        " salt=#{salt},\n" +
        " modifiedTime=now()\n" +
        " where id=#{id}")
    int updatePassword(
            @Param("password")String password,
            @Param("salt")String salt,
            @Param("id")Integer id);


}